﻿using Aspose.Pdf.Facades;
using Spire.Pdf.Conversion;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string filepath = AppDomain.CurrentDomain.BaseDirectory + "/ofd";
            DirectoryInfo directory = new DirectoryInfo(filepath);
            List<FileInfo> ofdFiles = GetFiles(directory, ".ofd");
            foreach (FileInfo fi in ofdFiles)
            {
                OfdConverter converter = new OfdConverter(fi.FullName);

                converter.ToPdf(fi.FullName.Replace(".ofd", ".pdf"));
            }
            List<FileInfo> pdfFiles = GetFiles(directory, ".pdf");
            foreach (FileInfo fi in pdfFiles)
            {
                ReplacePdfFiled(fi.FullName);
            }
            Console.WriteLine("All is done!");

            Console.ReadKey();
        }


        static List<FileInfo> GetFiles(DirectoryInfo folder, string fileExtension)
        {
            List<FileInfo> files = new List<FileInfo>();
            foreach (FileInfo fi in folder.EnumerateFiles())
            {
                if (fi.Extension.ToLower() == fileExtension)
                    files.Add(fi);
            }
            return files;
        }

        public static void ReplacePdfFiled(string pdffilepath)
        {
            string path = AppDomain.CurrentDomain.BaseDirectory + "/Aspose.Total.lic";
            Aspose.Pdf.License license = new Aspose.Pdf.License();
            license.SetLicense(path);  
            PdfContentEditor pdfContentEditor = new PdfContentEditor();
            pdfContentEditor.BindPdf(pdffilepath);
            pdfContentEditor.ReplaceText("Evaluation Warning : The document was created with Spire.PDF for .NET.", "");
            pdfContentEditor.Save(pdffilepath);
        }
    }
}
